import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/less/index.less'
import store from '../store'

import router from '../router';
import http from 'axios';
import '../api/mock'

// 滑动验证框
import SlideVerify from 'vue-monoplasty-slide-verify';
Vue.use(SlideVerify);

// 粒子特效
// import  VueParticles  from   'vue-particles'
// Vue.use(VueParticles)

// 全局引入ElementUI
Vue.use(ElementUI);
Vue.config.productionTip = false

Vue.prototype.$http = http

// 设置初始路由逻辑
router.beforeEach((to, from, next) => {
  store.commit('getToken')
  store.commit('addMenu')
  const token = store.state.user.token
  // 如果没有token且访问的不是登陆界面 那么都会被跳转到登陆界面
  if(!token && to.name !== 'login' ){
    next({ name : 'login' })
  }
  else if(to.name == 'Main'){
    next({ name : 'home' })
  }
  else if(token && to.name == 'login'){
    next({ name: 'home' })  
  }
  else{
    next()
  }
})

new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')
